﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;


namespace WebSite.Ajax
{
    public partial class FavoriteClick : System.Web.UI.Page
    {
        private string objectid = "";
        private string objecttype = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            objectid = Request.QueryString["objectid"] + "";
            objecttype = Request.QueryString["objecttype"] + "";

            Users uinfo = UserBase.GetCurrentUser();
            if (uinfo == null)
            {
                Response.Write("请先登录");
                return;
            }
            else
            {
                //判断该用户是否已经收藏过
                FavoriteHelper fhelper = new FavoriteHelper();
                Criteria c = new Criteria();
                c.Add(CriteriaType.Equals, "ObjectID", objectid);
                c.Add(CriteriaType.Equals, "ObjectType", objecttype);
                c.Add(CriteriaType.Equals, "UsersID", uinfo.ID);
                int count = fhelper.QueryFavoriteCountBySearch(c);
                if (count > 0)//已经收藏过
                {
                    Response.Write("已经收藏过");
                    return;
                }
                else
                {
                    Favorite finfo = new Favorite();

                    finfo.ObjectID = objectid;
                    finfo.ObjectType = Convert.ToInt32(objecttype);
                    finfo.UsersID = uinfo.ID;

                    fhelper.AddFavorite(finfo);

                    Response.Write("收藏成功");
                    return;
                }
            }
        }
    }
}